﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Microsoft.VisualBasic.FileIO;

using TreeAllLibrary;

namespace removeSurplusVideo
{
    static class Program
    {
        public static List<string> waitToDelMp4=new List<string>();
        public static List<string> webms=new List<string>();
        public static List<string> waitToDelFiles = new List<string>();

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        public static void pickDirName(TextBox tb)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult dr = fbd.ShowDialog();
            if (dr == DialogResult.OK)
            {
                if (string.IsNullOrEmpty(fbd.SelectedPath))
                {
                    MessageBox.Show("文件夹路径不能为空", "提示");
                    return;
                }
                tb.Text = fbd.SelectedPath;
            }     
        }

        public static void compare(Form1 f1)
        {
            TreeAllLibrary.TreeAllLibrary.getAllFilesIncludeAllSubDir(f1.textBox1.Text,waitToDelMp4);
            TreeAllLibrary.TreeAllLibrary.getAllFilesIncludeAllSubDir(f1.textBox2.Text,webms);
            for (int i = 0; i < webms.Count; i++)
            {
                string ext = System.IO.Path.GetExtension(webms[i]);
                if (ext == ".webm") continue;
                webms.RemoveAt(i);
                i--;
            }
            //
            foreach (string mp4 in waitToDelMp4)
            {
                if (System.IO.Path.GetExtension(mp4) != ".mp4") continue;
                foreach (string webm in webms)
                {
                    string fileName1 = System.IO.Path.GetFileNameWithoutExtension( mp4);
                    string fileName2 = System.IO.Path.GetFileNameWithoutExtension( webm);
                    if (fileName2.Contains(fileName1))
                    {
                        if (!waitToDelFiles.Contains(mp4)) 
                        {
                            waitToDelFiles.Add(mp4);
                        } 
                    }
                }
            }
            //
            f1.label2.Text = waitToDelFiles.Count.ToString();
        }

        public static void removeFiles()
        {
            foreach (string file in waitToDelFiles)
            {
                FileSystem.DeleteFile(file, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
            }
            string prompt=string.Format("已删除{0}个文件到回收站！",waitToDelFiles.Count);
            MessageBox.Show(prompt);
        }
    }
}
